/*
 * Project Name spring-boot-tools
 * File Name Gen
 * Package Name com.huxiaosu.tools.screw
 * Create Time 2024/9/11
 * Create by name：liujie
 */
package cn.smallbun.screw.core;

import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.util.ArrayList;

/**
 * Description
 *
 * @author liujie
 * @date 2024/9/11 14:00
 */
public class Gen {
    public static void main(String[] args) {
        //数据源
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
        hikariConfig.setJdbcUrl("jdbc:mysql://172.25.67.55:3306/adms_gov_dev");
        hikariConfig.setUsername("root");
        hikariConfig.setPassword("root@Adms,1234");
        //设置可以获取tables remarks信息
        hikariConfig.addDataSourceProperty("useInformationSchema", "true");
        hikariConfig.setMinimumIdle(2);
        hikariConfig.setMaximumPoolSize(5);
        DataSource dataSource = new HikariDataSource(hikariConfig);
        //生成配置
        EngineConfig engineConfig = EngineConfig.builder()
                //生成文件路径
                .fileOutputDir("/Users/liujie/Desktop/")
                //打开目录
                .openOutputDir(true)
                //文件类型
                .fileType(EngineFileType.WORD)
                //生成模板实现
                .produceType(EngineTemplateType.freemarker)
                //自定义文件名称
                .fileName("123").build();
        //忽略表
        ArrayList<String> genTableName = new ArrayList<>();
        genTableName.add("d_research_archive_exhibition");
        genTableName.add("d_research_archive_exhibition_file");
        genTableName.add("d_research_achievements");
        genTableName.add("d_research_topic");
        genTableName.add("d_research_topic_archive_material");
        genTableName.add("d_research_topic_material");
        genTableName.add("d_research_topic_outline");
        genTableName.add("d_research_topic_task");
        genTableName.add("d_research_topic_task_edit");
        genTableName.add("d_research_topic_task_edit_ai");
        genTableName.add("d_research_topic_task_outline");
        genTableName.add("d_research_topic_task_review");
        genTableName.add("d_research_topic_task_review_info");
        genTableName.add("d_special_topic");
        genTableName.add("d_topic_material_library");
        //忽略表前缀
        ArrayList<String> ignorePrefix = new ArrayList<>();
        ignorePrefix.add("act_");

        ProcessConfig processConfig = ProcessConfig.builder()
                //指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时，将生成指定表，其余表不生成、并跳过忽略表配置
                //根据名称指定表生成
                .designatedTableName(genTableName)
                //根据表前缀生成
                .designatedTablePrefix(new ArrayList<>())
                //根据表后缀生成
                .designatedTableSuffix(new ArrayList<>())
                //忽略表名
                .ignoreTableName(new ArrayList<>())
                //忽略表前缀
                .ignoreTablePrefix(ignorePrefix)
                //忽略表后缀
                .ignoreTableSuffix(new ArrayList<>()).build();
        //配置
        Configuration config = Configuration.builder()
                //版本
                .version("1.0.0")
                //描述
                .description("数据库设计文档生成")
                //数据源
                .dataSource(dataSource)
                //生成配置
                .engineConfig(engineConfig)
                //生成配置
                .produceConfig(processConfig)
                .build();
        //执行生成
        new DocumentationExecute(config).execute();
    }
}